<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Setor extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->verifySession();
        $this->load->view('header');
        $this->load->model('setor_model', '', TRUE);
        $this->load->model('nivel_model', '', TRUE);
    }

    public function exibir() {
        $this->load->view('setor/setor_exibir');
    }

    public function novoSetor($nivel = 0) {
        $this->load->library('form_validation');
        $this->form_validation->set_rules('setor', 'Setor', 'trim|required|xss_clean');
        
        if ($this->nivel_model->verificaNivel($nivel)):
            if (( $this->form_validation->run())):
                $this->setor_model->novoSetor($nivel, $this->input->post('setor'));
            $this->load->view('setor/setor_cadastrado');
            else:
                $data["nivel"] = $nivel;
                $this->load->view('setor/novo_setor', $data);
            endif;
        else:
            $data['error'] = "Nivel inexistente favor <a href=" . base_url("main/privateArea") . "selecionar novamente! </a>";
            $this->load->view('setor/setor_erro_cadastro', $data);
        endif;
    }

}